package org.example.mock.product.impl;

import org.example.product.api.SdkProductDTO;
import org.example.product.api.ProductService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    @Override
    public SdkProductDTO getProduct(String productId) {
        return createProductDTO(productId, 1);
    }

    @Override
    public List<SdkProductDTO> getProducts(List<String> productIds) {
        List<SdkProductDTO> result = new ArrayList<>();
        for (int i = 0; i < productIds.size(); i++) {
            result.add(createProductDTO(productIds.get(i), i + 1));
        }
        return result;
    }

    private SdkProductDTO createProductDTO(String productId, int index) {
        SdkProductDTO sdkProductDTO = new SdkProductDTO();
        sdkProductDTO.setId(productId);
        sdkProductDTO.setCode("code" + index);
        sdkProductDTO.setName("name" + index);
        return sdkProductDTO;
    }
}
